import { MachineBase } from "@/Battle/StateMechine/MachineBase.js";

import { BattleEventType } from "@/Battle/Event/BattleEvent.js";
import CombatEventBus from "@/Battle/CombatEventBus.js";
import { CombatEventPool } from "@/Battle/Event/CombatEventPool.js";

export class BattlePhaseMachine extends MachineBase{
    constructor(){
        super();
        this.addStateHandler('start',this.onBattleStartRequest);
        this.addStateHandler('end',this.onBattleEndRequest);
    }

    onBattleStartRequest=()=>{
        this.wait();
        CombatEventBus.dispatch(
            CombatEventPool.newCombatEvent(
                BattleEventType.Start.Request,
                this
            ),
            this.startBattle
        );
    }

    startBattle=()=>{
        this.wait();
        CombatEventBus.dispatch(
            CombatEventPool.newCombatEvent(
                BattleEventType.Start.Complete,
                this
            ),
            this.startRound
        );
    }

    startRound=()=>{
        this.tonext();
        this.end();
    }

    onBattleEndRequest=()=>{
        this.wait();
        CombatEventBus.dispatch(
            CombatEventPool.newCombatEvent(BattleEventType.End.Request,this),
            this.endBattle
        );
    }

    endBattle=()=>{
        this.wait();
        CombatEventBus.dispatch(
            CombatEventPool.newCombatEvent(
                BattleEventType.End.Complete,
                this
            )
        );
    }
}